﻿using QLXN.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLXN
{
    public partial class Login : hTekForm
    {
        public Login()
        {
            InitializeComponent();
        }

        SqlInteraction sql = new SqlInteraction();

        private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                string us = txt_us.Text.Trim();
                string pw = txt_pw.Text.Trim();
                string query = "SELECT * FROM qlxn_users WHERE username = N'" + us + "' AND password = N'" + pw + "'";
                DataTable dt = new DataTable();
                dt = sql.Execute_Table(query);
                if (dt.Rows.Count > 0)
                {
                    //MessageBox.Show(this, "Login successful!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Main main = new Main(us);
                    main.FormClosed += new FormClosedEventHandler(Main_FormClosed);
                    main.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(this, "Tên đăng nhập hoặc mật khẩu không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            { }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            DialogResult rs = MessageBox.Show(this, "Thoát chương trình?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (rs == DialogResult.Yes)
                this.Close();
        }

        void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Close();
        }
    }
}
